package com.chb.authentication;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description: 登陆成功执行策略
 * @author: CHB
 * @create: 2021-11-16 16:03
 **/
@Slf4j
public class CustomSavedRequestAwareAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
        System.out.println("handler发来贺电：登录成功");
        this.setDefaultTargetUrl("/index");
        log.info("LocalName: {}, RequestURL: {}, method: {}, session:{}"
                ,request.getLocalName(),request.getRequestURL(),request.getMethod(),request.getSession());
    }

}
